interface Point {
  readonly type: string;
}

const p: Point = { type: "Cirle" };
// p.type = "123"; //报错 因为type只读属性
// console.log(p);

interface SquareConfig {
  width?: number;
  color?: string;
  [confName: string]: any; //添加一个字符串索引签名 不添加 会报错 'colour' does not exist in type 'SquareConfig'
}

function createSquare(config: SquareConfig): SquareConfig {
  return config;
}

console.log(createSquare({ colour: "#f00", width: 20 }));

interface PersonInterface {
  name: string;
  getName(): String;
  setName(name: string): void;
}

export default class Person implements PersonInterface {
  name: string = "";
  getName() {
    return this.name;
  }
  setName(name: string) {
    this.name = name;
  }
  constructor(name?: string) {
    this.name = name;
  }
}

const lilei = new Person("Li Lei");
lilei.setName("hanmeimei");
console.log(lilei.getName());

interface ClockConstructor {
  new (hour: number, minute: number): ClockInterface;
}
interface ClockInterface {
  tick();
}

function createClock(ctor: ClockConstructor, hour: number, minute: number): ClockInterface {
  return new ctor(hour, minute);
}

class Clock implements ClockInterface {
  constructor(h: number, m: number) {}
  tick() {
    console.log("beep beep");
  }
}

let digital = createClock(Clock, 12, 17);
digital.tick();
